#include "Simulation.h"

Simulation::Simulation() {
  m_maxDelay = -1;
  m_totalDelay = 0;
  m_numCustomers = 0;
  m_currentTime = 0;
  m_averageDelay = -1;
}

Simulation::~Simulation() {}

void Simulation::processCustomers(Queue<Customer> &customers) {
  while (!customers.isEmpty()) {
    Customer customer = customers.dequeue();
    if (customer.getArrivalTime() > m_currentTime) {
      m_currentTime = customer.getArrivalTime();
    }
    int delay = m_currentTime - customer.getArrivalTime();
    if (delay > m_maxDelay) {
      m_maxDelay = delay;
    }
    m_totalDelay += delay;
    m_numCustomers++;
    m_currentTime += customer.getDurationTime();
  }

  if (m_numCustomers > 0) {
    m_averageDelay = (float)m_totalDelay / m_numCustomers;
  }
}

void Simulation::printStatistics() {
  std::cout << "Max Delay: " << m_maxDelay << std::endl;
  std::cout << "Average Delay: " << m_averageDelay << std::endl;
}
